﻿using ConfExpert.Forms.Base;
using DevTeam;
using System;
namespace ConfExpert.Forms
{
    public partial class Rx : XForm
    {
        string SP, Add, F0, F1, FK, Add_2, F0_2, F1_2;
        public Rx(string Name, string SP, string Add, string F0, string F1, string FK, string Add_2, string F0_2, string F1_2)
        {
            InitializeComponent();
            this.SP = SP;
            this.Add = Add;
            this.F0 = F0;
            this.F1 = F1;
            this.FK = FK;
            this.Add_2 = Add_2;
            this.F0_2 = F0_2;
            this.F1_2 = F1_2;
            this.Text += "- " + Name;
        }

        private void Rx_Load(object sender, EventArgs e)
        {
            if (FK == string.Empty)
            {
                splitContainerControl1.PanelVisibility = DevExpress.XtraEditors.SplitPanelVisibility.Panel1;
                gridView1.Init(SP);
                if (F0 != string.Empty)
                    gridView1.FormatAsNumber(0, F0.Split(','));
                if (F1 != string.Empty)
                    gridView1.FormatAsNumber(1, F1.Split(','));
                if (Add != string.Empty)
                    gridView1.AddSummary(Add.Split(','));
            }
            else
            {
                splitContainerControl1.AutoSize();
                gridView1.Init(SP);
                gridView1.AddDetailGrid(gridView2, FK);

                if (F0 != string.Empty)
                    gridView1.FormatAsNumber(0, F0.Split(','));
                if (F1 != string.Empty)
                    gridView1.FormatAsNumber(1, F1.Split(','));
                if (Add != string.Empty)
                    gridView1.AddSummary(Add.Split(','));

                if (F0_2 != string.Empty)
                    gridView2.FormatAsNumber(0, F0_2.Split(','));
                if (F1_2 != string.Empty)
                    gridView2.FormatAsNumber(1, F1_2.Split(','));
                if (Add_2 != string.Empty)
                    gridView2.AddSummary(Add_2.Split(','));

                gridView1.FocusedRowChanged += gridView1_FocusedRowChanged;
            }
            gridView1.MakeReadOnly();
            gridView2.MakeReadOnly();
            gridView1.BestFitColumns();
            gridView2.BestFitColumns();

        }

        void gridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            gridView2.BestFitColumns();
        }
    }
}